Date.prototype.Format = function (fmt) { //author: meizz 
	var o = {
	    "M+": this.getMonth() + 1, //月份 
	    "d+": this.getDate(), //日 
	    "h+": this.getHours(), //小时 
	    "m+": this.getMinutes(), //分 
	    "s+": this.getSeconds(), //秒 
	    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	    "S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}


// js获取某周、某月、上月、某季度的开始日期、结束日期及判断日期第几周
/**
 * 获取某周、某月、上月、某季度的开始日期、结束日期及判断日期第几周
 */
var formatDate = function(date) {
	var myyear = date.getFullYear();
	var mymonth = date.getMonth() + 1;
	var myweekday = date.getDate();

	if (mymonth < 10) {
		mymonth = "0" + mymonth;
	}
	if (myweekday < 10) {
		myweekday = "0" + myweekday;
	}
	return (myyear + "-" + mymonth + "-" + myweekday);
}


var getMonthDays = function(paraYear, paraMonth) {
	var monthStartDate = new Date(paraYear, paraMonth, 1);
	var monthEndDate = new Date(paraYear, paraMonth + 1, 1);
	var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
	return days;
}

var getWeekStartDate = function (paraYear, paraMonth, paraDay, paraDayOfWeek) {
	var weekStartDate = new Date(paraYear, paraMonth, paraDay + 1
			- paraDayOfWeek);
	return formatDate(weekStartDate);
}

var getWeekEndDate = function (paraYear, paraMonth, paraDay, paraDayOfWeek) {
	var weekEndDate = new Date(paraYear, paraMonth, paraDay
			+ (7 - paraDayOfWeek));
	return formatDate(weekEndDate);
}

var getMonthStartDate = function (paraYear, paraMonth) {
	var monthStartDate = new Date(paraYear, paraMonth, 1);
	return formatDate(monthStartDate);
}

var getMonthEndDate = function (paraYear, paraMonth) {
	var monthEndDate = new Date(paraYear, paraMonth, getMonthDays(paraYear,
			paraMonth));
	return formatDate(monthEndDate);
}

var getMonthStartDate1 = function (paraYear, paraMonth) {
	var monthStartDate = new Date(paraYear, paraMonth, 1);
	return formatDateBegin(monthStartDate);
}

var getMonthEndDate1 = function (paraYear, paraMonth) {
	var monthEndDate = new Date(paraYear, paraMonth, getMonthDays(paraYear,
			paraMonth));
	return formatDateEnd(monthEndDate);
}

var getLastMonthStartDate = function (paraYear, lastMonth) {
	var lastMonthStartDate = new Date(paraYear, lastMonth, 1);
	return formatDate(lastMonthStartDate);
}

var getLastMonthEndDate = function (paraYear, lastMonth, lastMonth) {
	var lastMonthEndDate = new Date(paraYear, lastMonth,
			getMonthDays(lastMonth));
	return formatDate(lastMonthEndDate);
}

var getQuarterStartDate = function (paraYear, paraSeason) {
	switch (paraSeason) {
	case '1':
		return paraYear + "-01-01";
	case '2':
		return paraYear + "-04-01";
	case '3':
		return paraYear + "-07-01";
	case '4':
		return paraYear + "-10-01";
	}
}


var getQuarterEndDate = function (paraYear, paraSeason) {
	switch (paraSeason) {
	case '1':
		return paraYear + "-03-31";
	case '2':
		return paraYear + "-06-30";
	case '3':
		return paraYear + "-09-30";
	case '4':
		return paraYear + "-12-31";
	}
}

var getBeginDateOfWeek1 = function (paraYear, weekIndex) {
	var firstDay = GetFirstWeekBegDay(paraYear);
	// 7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
	var time = (weekIndex - 1) * 7 * 24 * 3600000;
	var beginDay = firstDay;
	// 为日期对象 date 重新设置成时间 time
	beginDay.setTime(firstDay.valueOf() + time);
	return formatDate(beginDay);
}

var getEndDateOfWeek1 = function (paraYear, weekIndex) {
	var firstDay = GetFirstWeekBegDay(paraYear);
	// 7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
	var time = (weekIndex - 1) * 7 * 24 * 3600000;
	var weekTime = 6 * 24 * 3600000;
	var endDay = firstDay;
	// 为日期对象 date 重新设置成时间 time
	endDay.setTime(firstDay.valueOf() + weekTime + time);
	return formatDate(endDay);
}

var getBeginDateOfWeek = function (paraYear, weekIndex) {
	var firstDay = GetFirstWeekBegDay(paraYear);
	// 7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
	var time = (weekIndex - 1) * 7 * 24 * 3600000;
	var beginDay = firstDay;
	// 为日期对象 date 重新设置成时间 time
	beginDay.setTime(firstDay.valueOf() + time);
	return formatDateBegin(beginDay);
}

var getEndDateOfWeek = function (paraYear, weekIndex) {
	var firstDay = GetFirstWeekBegDay(paraYear);
	// 7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
	var time = (weekIndex - 1) * 7 * 24 * 3600000;
	var weekTime = 6 * 24 * 3600000;
	var endDay = firstDay;
	// 为日期对象 date 重新设置成时间 time
	endDay.setTime(firstDay.valueOf() + weekTime + time);
	return formatDateEnd(endDay);
}

var GetWeekIndex = function (dateobj) {
	var firstDay = GetFirstWeekBegDay(dateobj.getFullYear());
	if (dateobj < firstDay) {
		firstDay = GetFirstWeekBegDay(dateobj.getFullYear() - 1);
	}
	d = Math.floor((dateobj.valueOf() - firstDay.valueOf()) / 86400000);
	return Math.floor(d / 7) + 1;
}
var GetFirstWeekBegDay = function (year) {
	var tempdate = new Date(year, 0, 1);
	var temp = tempdate.getDay();
	if (temp == 1) {
		return tempdate;
	}
	temp = temp == 0 ? 7 : temp;
	tempdate = tempdate.setDate(tempdate.getDate() + (8 - temp));
	return new Date(tempdate);
}

function getWeek(date) {
	var week;
	if (new Date(date).getDay() == 0)
		week = "星期日"
	if (new Date(date).getDay() == 1)
		week = "星期一"
	if (new Date(date).getDay() == 2)
		week = "星期二"
	if (new Date(date).getDay() == 3)
		week = "星期三"
	if (new Date(date).getDay() == 4)
		week = "星期四"
	if (new Date(date).getDay() == 5)
		week = "星期五"
	if (new Date(date).getDay() == 6)
		week = "星期六"
	return week;
}


/**
 * 周报日期格式化
 * 
 * @param date
 * @returns {String}
 */
var formatDateBegin = function (date) {
	var myyear = date.getFullYear();
	var mymonth = date.getMonth() + 1;
	var myweekday = date.getDate();

	if (mymonth < 10) {
		mymonth = "0" + mymonth;
	}
	if (myweekday < 10) {
		myweekday = "0" + myweekday;
	}
	return (myyear + "年" + mymonth + "月" + myweekday + "日");
}

var formatDateEnd = function (date) {
	var myyear = date.getFullYear();
	var mymonth = date.getMonth() + 1;
	var myweekday = date.getDate();

	if (mymonth < 10) {
		mymonth = "0" + mymonth;
	}
	if (myweekday < 10) {
		myweekday = "0" + myweekday;
	}
	return (mymonth + "月" + myweekday + "日");
}

var getDateRange = function (year, index, type) {	
	if(type == "w"){
		return getBeginDateOfWeek(year, index) 
			+ "-" 
			+ getEndDateOfWeek(year, index);
    }
    else if(type == "m"){
		return getMonthStartDate1(year, index) 
			+ "-" 
			+ getMonthEndDate1(year, index);       
    }
};
var addDays = function(date, value) 
{ 
	date.setDate(date.getDate()+value); 
	return date;
};
var addMinutes = function(date, value) 
{ 
	date.setMinutes(date.getMinutes()+value); 
	return date;
};


// 格式化日期：yyyy-MM-dd
exports.formatDate = formatDate;
// 获得某月的天数
exports.getMonthDays = getMonthDays;
// 获得某周的开始日期
exports.getWeekStartDate = getWeekStartDate;
// 获得某周的结束日期
exports.getWeekEndDate = getWeekEndDate;
// 获得某月的开始日期
exports.getMonthStartDate = getMonthStartDate;
// 获得某月的结束日期
exports.getMonthEndDate = getMonthEndDate;
// 获得某月的开始日期
exports.getMonthStartDate1 = getMonthStartDate1;
// 获得某月的结束日期
exports.getMonthEndDate1 = getMonthEndDate1;
// 获得上月开始时间
exports.getLastMonthStartDate = getLastMonthStartDate;
// 获得上月结束时间
exports.getLastMonthEndDate = getLastMonthEndDate;
// 获得某季度的开始日期
exports.getQuarterStartDate = getQuarterStartDate;
// 获得某季度的结束日期
exports.getQuarterEndDate = getQuarterEndDate;
//获取某年某周的开始日期
exports.getBeginDateOfWeek1 = getBeginDateOfWeek1;
//获取某年某周的结束日期
exports.getEndDateOfWeek1 = getEndDateOfWeek1;
// 获取某年某周的开始日期
exports.getBeginDateOfWeek = getBeginDateOfWeek;
// 获取某年某周的结束日期
exports.getEndDateOfWeek = getEndDateOfWeek;
// 获取日期为某年的第几周
exports.GetWeekIndex = GetWeekIndex;
// 获取某年的第一天
exports.GetFirstWeekBegDay = GetFirstWeekBegDay;
// 周报日期格式化
exports.formatDateBegin = formatDateBegin;
// 周报日期格式化
exports.formatDateEnd = formatDateEnd;
// 获取日期的范围 2014年11月17日 - 11月23日
exports.getDateRange = getDateRange;
exports.addDays = addDays;
exports.addMinutes = addMinutes;